package com.ngu.util;

import org.omg.CORBA.INTERNAL;

/**
* @Description:    对数据进行封装返回给前端
* @Author:         hq
* @CreateDate:     2019/9/28 2019/9/28
* @UpdateUser:     hq
* @UpdateDate:     2019/9/28 2019/9/28
* @UpdateRemark:   修改内容
* @Version:        1.0
*/
public class AjaxResponse {
    //返回msg
    private String msg;

    //返回参数
    private Object data;

    //返回code
    private String code;

    //返回总数
    private Integer count;

    //返回当前页数
    private Integer pageIndex;



    //定义一个通用的正确创建方法
    public static AjaxResponse success(String msg){
        AjaxResponse type = new AjaxResponse();
        type.setMsg(msg);
        return  type;
    }
    //定义一个通用的正确创建方法
    public static AjaxResponse success(String msg,String code){
        AjaxResponse type = new AjaxResponse();
        type.setMsg(msg);
        type.setCode(code);
        return  type;
    }

    public static AjaxResponse success(String msg,String code,Object data){
        AjaxResponse type = new AjaxResponse();
        type.setMsg(msg);
        type.setCode(code);
        type.setData(data);
        return  type;
    }

    public static AjaxResponse pageResponse(String msg,Object data,Integer count,Integer pageIndex){
        AjaxResponse type = new AjaxResponse();
        type.setMsg(msg);
        type.setCode("0");
        type.setData(data);
        type.setCount(count);
        type.setPageIndex(pageIndex);
        return  type;
    }


    //定义一个通用的请求错误的创建方法
    public static AjaxResponse error(String msg){
        AjaxResponse type = new AjaxResponse();
        type.setMsg(msg);
        return  type;
    }
    //定义一个通用的正确创建方法
    public static AjaxResponse error(String msg,String code){
        AjaxResponse type = new AjaxResponse();
        type.setMsg(msg);
        type.setCode(code);
        return  type;
    }

    public static AjaxResponse error(String msg,String code,Object data){
        AjaxResponse type = new AjaxResponse();
        type.setMsg(msg);
        type.setCode(code);
        type.setData(data);
        return  type;
    }



    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }
}
